import Vue from 'vue'
import Vuex from 'vuex'
import tab from './tab'
import user from './user.js'
//1.引入Vuex模块，对Vuex模块进行全局注入
Vue.use(Vuex)

//2.创建Vuex实例，即为store
export default new Vuex.Store({
	state: {
		currentPathName: '',
		isLogin: '0',
		token: localStorage.getItem('token') ? localStorage.getItem('token') : '', // token
	},
	getters: {
		// 监听数据变化的
		getStorage(state) { // 获取本地存储的登录信息
			if (!state.token) {
				state.token = JSON.parse(localStorage.getItem(token))
			}
			return state.token
		},
	},
	mutations: {
		setPath(state) {
			state.currentPathName = localStorage.getItem('currentPathName');
		},
		setLogin(state, payload) {
			state.token = payload.token
			state.isLogin = payload.isLogin
			state.usertype = payload.usertype
		},
		logout() {
			localStorage.removeItem("user")
			localStorage.removeItem("currentPathName")
			localStorage.removeItem("menus")
			resetRoutes();
			router.push('/login');
		}
	},
	actions: {},
	modules: {
		tab,
		user
	}
})	